Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Large Index Support for Slice #15593

Merged
merged 8 commits into from
Aug 13, 2019
Merged

Large Index Support for Slice #15593

merged 8 commits into from
Aug 13, 2019

Conversation

access2rohit
Copy link
Contributor

@access2rohit access2rohit commented Jul 18, 2019

Description

Ops Supported: Slice

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html

@access2rohit
Copy link
Contributor Author

@mxnet-label-bot add [pr-work-in-progress]

hdl = NDArrayHandle()
check_call(_LIB.MXNDArrayCreateEx(
c_array_buf(mx_uint, native_array('I', shape)),
mx_uint(len(shape)),
c_array_buf(mx_int64, native_array('q', shape)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check python version if 'q' is supported

#if MXNET_USE_INT64_TENSOR_SIZE == 1
return MXNDArrayCreateExInt<int64_t>(shape, ndim, dev_type, dev_id, delay_alloc, dtype, out);
#else
return MXNDArrayCreateExInt<int32_t>(shape, ndim, dev_type, dev_id, delay_alloc, dtype, out);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not work. You can't just cast a mx_int64 pointer to int32_t pointer.

@@ -195,6 +196,20 @@ int MXNDArrayCreateEx(const mx_uint *shape,
API_END();
}

int MXNDArrayCreateEx(const mx_int64 *shape,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also you are directly changing this C API which might break other language bindings that use this C API.

@@ -802,7 +807,8 @@ MXNET_DLL int MXNDArrayGetShape(NDArrayHandle handle,
*/
MXNET_DLL int MXNDArrayGetShapeEx(NDArrayHandle handle,
int *out_dim,
const int **out_pdata);
const int64_t **out_pdata);
Copy link
Contributor

@apeforest apeforest Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are directly modifying C API which may break other language bindings. As we have agreed, it may be safer to create additional 64bit APIs instead.

@@ -55,7 +55,8 @@ extern "C" {
#endif

/*! \brief manually define unsigned int */
typedef unsigned int mx_uint;
typedef int64_t mx_int64;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit but,
As per the comment
/*! \brief manually define unsigned int */
Line
typedef int64_t mx_int64; should be above it I guess, as it is not unsigned.

@@ -548,15 +549,14 @@ MXNET_DLL int MXNDArrayCreate(const mx_uint *shape,
* \param out the returning handle
* \return 0 when success, -1 when failure happens
*/
MXNET_DLL int MXNDArrayCreateEx(const mx_uint *shape,
MXNET_DLL int MXNDArrayCreateEx(const mx_int64 *shape,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry if this is a stupid question, but why are we replacing mx_uint (unsigned) with mx_int64 (signed)?
I would assume shape is always positive, shouldn't it be mx_uint64?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two reasons:
(1) According to Google C++ style guide: "Do not use an unsigned type merely to assert that a variable is non-negative." https://google.github.io/styleguide/cppguide.html#Integer_Types

(2) We intentionally changed to int because we may reserve the index -1 for supporting empty tensor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Thank You for the explanation.

@access2rohit access2rohit force-pushed the lis_slice branch 2 times, most recently from 8fcde44 to 2d31323 Compare July 19, 2019 17:38
@@ -513,6 +529,34 @@ int MXNDArrayGetShape(NDArrayHandle handle,
API_END();
}

int MXNDArrayGetShapeExInt64(NDArrayHandle handle,
int *out_dim,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

@access2rohit access2rohit force-pushed the lis_slice branch 4 times, most recently from 9cebf08 to fb9540e Compare July 19, 2019 21:43

MXNET_DLL int MXNDArrayGetShapeExInt64(NDArrayHandle handle,
int *out_dim,
const int64_t **out_pdata);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use mx_int64 to be consistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@access2rohit
Copy link
Contributor Author

@mxnet-label-bot add [pr-awaiting-review]

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Jul 19, 2019
@access2rohit access2rohit changed the title [WIP]Large Index Support Large Index Support for Slice Jul 19, 2019
Copy link
Contributor

@ChaiBapchya ChaiBapchya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor changes!
Also, c_api_common.h and c_api_symbolic.cc still use int64_t (simple find for int64_t shows there are 22 places it's being used currently in the PR. Wanted clarity on what's the norm? When to use int64_t and when to use mx_int64? Is it even needed?)

src/c_api/c_api.cc Show resolved Hide resolved
src/operator/tensor/matrix_op-inl.h Show resolved Hide resolved
@access2rohit
Copy link
Contributor Author

@ChaiBapchya mx_uint is used for maintaining consistency with language bindings. For example python uses mx_int64 = ctype.c_int64 and its counter part in C++ is typedef int64_t mx_int64 this way we can ensure both signature have same data types. one exception to it is int which on python side is mx_int but on C++ its just int

@access2rohit
Copy link
Contributor Author

@mxnet-label-bot add[pr-awaiting-merge]

@marcoabreu marcoabreu added the pr-awaiting-merge Review and CI is complete. Ready to Merge label Aug 8, 2019
@@ -105,6 +107,8 @@
_NDARRAY_BASIC_INDEXING = 0
_NDARRAY_ADVANCED_INDEXING = 1

# Caching whether MXNet was built with INT64 support or not
_INT64_TENSOR_SIZE_ENABLED = Features().is_enabled('INT64_TENSOR_SIZE')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still not efficient as Features() is still called everytime this variable is evaluated. There is no const variable in Python as in C++

@access2rohit access2rohit force-pushed the lis_slice branch 6 times, most recently from e5e382a to 458b1ae Compare August 12, 2019 16:19
const mx_int64 **out_pdata) {
MXAPIThreadLocalEntry<int64_t> *ret = MXAPIThreadLocalStore<int64_t>::Get();
API_BEGIN();
GetShape<mx_int64>(handle, out_pdata, out_dim, ret);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mx_int64 and int64_t are mixed here. Please consolidate them in your next PR.

Copy link
Contributor

@apeforest apeforest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@apeforest apeforest merged commit 05f3ae1 into apache:master Aug 13, 2019
anirudhacharya pushed a commit to anirudhacharya/mxnet that referenced this pull request Aug 20, 2019
* Adding Large Index Support for slice operator

* adding changes to fix py2 related error in CI/CD

* fixing base.py

* rearrange system call and slower Feature() call

* refactoring c_api, c_symbolic_api, c_api_common

* templatizing code

* caching results of runtime features and minor refactoring

* fixing local caching in ndarray shape
access2rohit added a commit to access2rohit/incubator-mxnet that referenced this pull request Sep 25, 2019
* Adding Large Index Support for slice operator

* adding changes to fix py2 related error in CI/CD

* fixing base.py

* rearrange system call and slower Feature() call

* refactoring c_api, c_symbolic_api, c_api_common

* templatizing code

* caching results of runtime features and minor refactoring

* fixing local caching in ndarray shape
access2rohit added a commit to access2rohit/incubator-mxnet that referenced this pull request Sep 25, 2019
* Adding Large Index Support for slice operator

* adding changes to fix py2 related error in CI/CD

* fixing base.py

* rearrange system call and slower Feature() call

* refactoring c_api, c_symbolic_api, c_api_common

* templatizing code

* caching results of runtime features and minor refactoring

* fixing local caching in ndarray shape
access2rohit added a commit to access2rohit/incubator-mxnet that referenced this pull request Sep 25, 2019
* Adding Large Index Support for slice operator

* adding changes to fix py2 related error in CI/CD

* fixing base.py

* rearrange system call and slower Feature() call

* refactoring c_api, c_symbolic_api, c_api_common

* templatizing code

* caching results of runtime features and minor refactoring

* fixing local caching in ndarray shape
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr-awaiting-merge Review and CI is complete. Ready to Merge pr-awaiting-review PR is waiting for code review pr-work-in-progress PR is still work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants